package uk.org.wookey.jpet;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import uk.org.wookey.jpet.model.CoreDBModel;


public class MainApplication extends JFrame {
	public MainApplication() {
		super("Teachers Pet");
		
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (Exception e) {
		    // If Nimbus is not available, you can set the GUI to another look and feel.
		}

		Toolkit tk = Toolkit.getDefaultToolkit();
		int xSize = tk.getScreenSize().width;
		int ySize = tk.getScreenSize().height;
		
		if (xSize > 1360) {
			xSize = 1360;
		}
		
		if (ySize > 768) {
			ySize = 768;
		}
		
		setSize(xSize, ySize);
		setLocation((tk.getScreenSize().width - xSize) / 2, (tk.getScreenSize().height - ySize) / 2);

		setLayout(new BorderLayout());
		
		MySqlDb dbh = new MySqlDb("localhost/pet", "root", "storemand");

		String tables[] = dbh.getTableNames();
		System.out.println("TABLES:");
		for (String table: tables) {
			System.out.println("  " + table);
			
			String columns[] = dbh.getColumnNames(table);
			for (String column: columns) {
				System.out.println("    " + column);
			}
		}
		
		DbModel data = new DbModel("SELECT * FROM students ORDER BY FirstName");
		JTable grid = new JTable(data);
		
		add(grid);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		pack();
		setVisible(true);
		
	}

	public static void main(String[] args) {
		new MainApplication();
	}
}
